import matplotlib.pyplot as plt
import numpy as np

# Données initiales (en mmol)
ni_MnO4 = 2.0       # ions permanganate
ni_ferreux = 12.5   # ions Fe2+

# Coefficients stœchiométriques (1 MnO4- + 5 Fe2+ → 1 Mn2+ + 5 Fe3+)
coeff_MnO4 = 1
coeff_Fe2 = 5

# Calcul de l’avancement maximal (x max)
x_max = min(ni_MnO4 / coeff_MnO4, ni_ferreux / coeff_Fe2)

# Valeurs de l’avancement
x = np.arange(0, x_max + 0.05, 0.05)

# Quantités de matière en fonction de x
n_MnO4 = np.clip(ni_MnO4 - coeff_MnO4 * x, 0, None)
n_Fe2  = np.clip(ni_ferreux - coeff_Fe2 * x, 0, None)

# Affichage
plt.plot(x, n_MnO4, color="red", label='MnO₄⁻')
plt.plot(x, n_Fe2,  color="green", label='Fe²⁺')
plt.scatter(x, n_MnO4, color='black', marker='+', s=30)
plt.scatter(x, n_Fe2,  color='black', marker='.', s=25)

plt.title("Évolution des quantités de matière")
plt.xlabel("Avancement x (mmol)")
plt.ylabel("Quantité (mmol)")
plt.grid(True)
plt.legend()
plt.show()

